//
//  FBFilesTableViewController.m
//  FileBrowser
//
//  Created by Steven Troughton-Smith on 18/06/2013.
//  Copyright (c) 2013 High Caffeine Content. All rights reserved.
//

#import <Masonry.h>
#import <SSZipArchive.h>
#import "SandBoxTool.h"
#import "WaterMarkTool.h"
#import <MWPhotoBrowser.h>

@interface SandBoxTool ()<MWPhotoBrowserDelegate>
@property (nonatomic, copy) NSString *folderBase;
@property (nonatomic, copy) NSString *picBase;
@property (nonatomic, copy) NSString *groupIdentifier;
@property (nonatomic, copy) NSString *groupContainer;

@property (nonatomic, strong) NSMutableArray<MWPhoto*> *photos;

@end

@implementation SandBoxTool


+ (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    UIViewController *vc = (UIViewController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
    [[NSUserDefaults standardUserDefaults] setObject:[url path] forKey:@"sandbox_import_path"];
    SandBoxTool *st = [[SandBoxTool alloc] initWithGroupIdentifier:group_identifier];
    [vc presentViewController:[[UINavigationController alloc] initWithRootViewController:st] animated:YES completion:nil];
    return YES;
}


- (instancetype)initWithStyle:(UITableViewStyle)style {
    self.folderBase = @"iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyhpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW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YPfShnxPfid2PfYuxdnrl9dBPaqqz1FsMQGOOPLjnfdsDLDGc741r+LyplQbdiNbPVq96GW2DuFjqntARENnzu29P1zw98eTR7cy6dVpj8pjl9ZyC3UqE9XfyhClqUODaeNgfSPbtS43NtHO/hFCorLcLd57GD1nfnxuUaOSkZhIUo+ZC3wHpizre9387gNvLe80qxXHNeFzhGZIS0WN8NRAxjw/bfm58sOTFX3GwXXtRkh26PPnuw6dyDqMX+5WS47NYe5oPdRPdRlJaOf5UmcPXte6BfZ2osfFgyVbPFbePCCFqM7qv3lVzMhXXnw++7Z80JnB6LH+iJ1Kgf1exZbPYGuAJLgmbHUnli/l8/MAaOe/Uq6RflErmWo+N79SbEDSTlIwO+MJUcz1uf0mbmmx16Zqv58rtFwmUqCDVyROT4Tt+mP6d85EjvWbe3hHfHDePQ4W3YvL7WmV9xii4LpIY30RdWxTvNkT8hS8d7eCz+8Z6dBFD05DEEcDAU/pLvgLx/+/hLAg73+X4ABAOpiy7lnUM1dAAAAAElFTkSuQmCC";
    return [super initWithStyle:style];
}

- (id)initWithGroupIdentifier:(NSString *)identifier {
    self = [self initWithStyle:UITableViewStylePlain];
    if(self) {
        self.groupIdentifier = identifier;
        self.files = [@[NSHomeDirectory()] mutableCopy];
        if(identifier) {
            self.groupContainer = [[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:identifier] path];
            [[NSUserDefaults standardUserDefaults] setObject:self.groupContainer forKey:@"sandbox_group_identifier"];
            [self.files addObject:self.groupContainer];
        }
    }
    return self;
}

- (id)initWithPath:(NSString *)path {
    self = [self initWithStyle:UITableViewStylePlain];
    if (self) {
        
		self.path = path;
        
		self.title = [path lastPathComponent];
		
		NSError *error = nil;
		NSMutableArray *tempFiles = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error] mutableCopy];
    
		if (error)
		{
			NSLog(@"ERROR: %@", error);
			
			if ([path isEqualToString:@"/System"])
				tempFiles = [@[@"Library"] mutableCopy];
			
			if ([path isEqualToString:@"/Library"])
				tempFiles = [@[@"Preferences"] mutableCopy];
			
			if ([path isEqualToString:@"/var"])
				tempFiles = [@[@"mobile"] mutableCopy];
			
			if ([path isEqualToString:@"/usr"])
				tempFiles = [@[@"lib", @"libexec", @"bin"] mutableCopy];
		}
		
		self.files = [[tempFiles sortedArrayWithOptions:0 usingComparator:^NSComparisonResult(NSString* file1, NSString* file2) {
			NSString *newPath1 = [self.path stringByAppendingPathComponent:file1];
			NSString *newPath2 = [self.path stringByAppendingPathComponent:file2];
            
			BOOL isDirectory1, isDirectory2;
			[[NSFileManager defaultManager ] fileExistsAtPath:newPath1 isDirectory:&isDirectory1];
			[[NSFileManager defaultManager ] fileExistsAtPath:newPath2 isDirectory:&isDirectory2];
			
			if (isDirectory1 && !isDirectory2)
				return NSOrderedDescending;
			
			return  NSOrderedAscending;
		}] mutableCopy];
        
        for(NSString *file in [self.files copy]) {
            NSString *f = [self.path stringByAppendingPathComponent:file];
            if([f containsString:@".com.apple.mobile"]) {
                [self.files removeObject:file];
            }
            if([[file pathExtension] isEqualToString:@"png"]) {
                if(!self.photos)
                    self.photos = [NSMutableArray array];
                [self.photos addObject:[MWPhoto photoWithURL:[NSURL fileURLWithPath:[self.path stringByAppendingPathComponent:file]]]];
            }
        }
        
    }

    return self;
}


- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSMutableArray *pathList = [NSMutableArray array];
    for(int i = 1; i < self.navigationController.viewControllers.count; i++) {
        SandBoxTool *vc = (SandBoxTool *)self.navigationController.viewControllers[i];
        [pathList addObject:vc.path];
    }
    [[NSUserDefaults standardUserDefaults] setObject:pathList forKey:@"sandbox_last_path"];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)dealloc {
#if __has_feature(objc_arc)
#else
    [super dealloc];
#endif
    NSLog(@"调用函数：%s",__func__);
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.tableView registerClass:[FBTableViewCell class] forCellReuseIdentifier:@"FileCell"];
    self.tableView.tableFooterView = [UIView new];
    if([self.path isEqualToString:NSHomeDirectory()]) {
        self.title = @"沙盒";
    }
    if(!self.title)
        self.title = @"浏览文件";
    
    UIActivityIndicatorView *ai = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    ai.frame = CGRectMake(0, 0, 80, 80);
    [self.view addSubview:ai];
    ai.center = CGPointMake(self.view.center.x, self.view.center.y-100);
    ai.hidesWhenStopped = YES;
    self.ai = ai;
}

- (void)newFolder:(UIBarButtonItem*)btnItem {
    NSString *importPath = [[NSUserDefaults standardUserDefaults] objectForKey:@"sandbox_import_path"];
    
    if(importPath) {
        NSString *target = [self.path stringByAppendingPathComponent:[importPath lastPathComponent]];
        if([self.files containsObject:[importPath lastPathComponent]] &&
           [[NSFileManager defaultManager] fileExistsAtPath:target]) {
            [[NSFileManager defaultManager] removeItemAtPath:target error:nil];
            [self.files removeObject:[importPath lastPathComponent]];
        }
        
        [self.ai startAnimating];
        
        if([[[target lastPathComponent] pathExtension] containsString:@"zip"]) {
            target = [target stringByReplacingOccurrencesOfString:@".zip" withString:@""];
            
            [SSZipArchive unzipFileAtPath:importPath toDestination:target];
        }else {
            [[NSFileManager defaultManager] copyItemAtPath:importPath toPath:target error:nil];
        }
        
        if(delete_after_imported) {
            [[NSFileManager defaultManager] removeItemAtPath:importPath error:nil];
        }
        
        [self.files addObject:[target lastPathComponent]];
        [self.tableView reloadData];
        [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"sandbox_import_path"];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"新建" style:UIBarButtonItemStylePlain target:self action:@selector(newFolder:)];
        [self.ai stopAnimating];
        return;
    }
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"新建文件夹" message:nil preferredStyle:UIAlertControllerStyleAlert];
    __block UITextField *field = nil;
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"文件夹名称";
        field = textField;
    }];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSString *directryPath = [self.path stringByAppendingPathComponent:field.text];
        [fileManager createDirectoryAtPath:directryPath withIntermediateDirectories:YES attributes:nil error:nil];
        
        if([fileManager fileExistsAtPath:[self.path stringByAppendingPathComponent:field.text]]) {
            [self.files addObject:field.text];
            [self.tableView reloadData];
        }
    }]];
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    __weak typeof(self) weakSelf = self;
    [[NSNotificationCenter defaultCenter] addObserverForName:@"event" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
        __block typeof(weakSelf) self = weakSelf;
        NSString *file =  note.object;
        if([self.files containsObject:[file lastPathComponent]]) {
            [self.files removeObject:[file lastPathComponent]];
            [self.tableView reloadData];
            return;
        }
        
        if(![self.files containsObject:[file lastPathComponent]] &&
           [file containsString:@".zip"] &&
           [[NSFileManager defaultManager] fileExistsAtPath:[self.path stringByAppendingPathComponent:file.lastPathComponent]]) {
            [self.files addObject:[file lastPathComponent]];
            [self.tableView reloadData];
            
            return;
        }
        
    }];
    
    [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillTerminateNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
        __block typeof(weakSelf) self = weakSelf;
        NSMutableArray *pathList = [NSMutableArray array];
        for(int i = 1; i < self.navigationController.viewControllers.count; i++) {
            SandBoxTool *vc = (SandBoxTool *)self.navigationController.viewControllers[i];
            [pathList addObject:vc.path];
        }
        [[NSUserDefaults standardUserDefaults] setObject:pathList forKey:@"sandbox_last_path"];
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    
    if(![self.title isEqualToString:@"浏览文件"] &&
       ![self.title isEqualToString:@"沙盒"]) {
        UIBarButtonItem *newFolder = nil;
        
        if([[NSUserDefaults standardUserDefaults] objectForKey:@"sandbox_import_path"]) {
            newFolder = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(newFolder:)];
            self.navigationItem.rightBarButtonItems = @[newFolder];
        }else {
            newFolder = [[UIBarButtonItem alloc] initWithTitle:@"新建" style:UIBarButtonItemStylePlain target:self action:@selector(newFolder:)];
            UIBarButtonItem *addWaterMark = [[UIBarButtonItem alloc] initWithTitle:@"处理图片" style:UIBarButtonItemStylePlain target:self action:@selector(handleImages)];
            self.navigationItem.rightBarButtonItems = @[newFolder, addWaterMark];
        }
        
    }
    
    if([self.title isEqualToString:@"浏览文件"]) {
        if([[NSUserDefaults standardUserDefaults] objectForKey:@"sandbox_import_path"]) {
            [self.files removeLastObject];
        }else {
            if(![self.files containsObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"sandbox_group_identifier"]]) {
                [self.files addObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"sandbox_group_identifier"]];
            }
        }
        [self.tableView reloadData];
    }
    
}

- (void)handleImages {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"处理图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alert addAction:[UIAlertAction actionWithTitle:@"加水印" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self addWaterMark];
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"处理方图-600*600" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [WaterMarkTool recursiveHandleSize:self.path width: 600];
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"处理手机截图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [WaterMarkTool recursiveScreeenShotHandleSize:self.path];
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    
    [self presentViewController:alert animated:YES completion:nil];
    
}


- (void)addWaterMark {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"添加水印" message:nil preferredStyle:UIAlertControllerStyleAlert];
    __block UITextField *field = nil;
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"水印文字";
        if([[NSUserDefaults standardUserDefaults] objectForKey:@"sandbox_waterMark_content"]) {
            textField.placeholder = [[NSUserDefaults standardUserDefaults] objectForKey:@"sandbox_waterMark_content"];
        }
        field = textField;
    }];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self.ai startAnimating];
        NSString *mark = field.text;
        if(mark &&
           ![mark isEqualToString:@""]) {
            [[NSUserDefaults standardUserDefaults] setObject:mark forKey:@"sandbox_waterMark_content"];
        }else {
            mark = field.placeholder;
        }
        [WaterMarkTool recursiveAddWaterMark:self.path title:mark];
        [self.ai stopAnimating];
    }]];
    
    [self presentViewController:alert animated:YES completion:nil];
    
    
    

}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
//    NSLog(@"numof---count:%lu",(unsigned long)self.files.count);
    return self.files.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"FileCell";
    FBTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
	if (!cell)
		cell = [[FBTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
	
	NSString *newPath = [self.path stringByAppendingPathComponent:self.files[indexPath.row]];
	
    cell.textLabel.text = self.files[indexPath.row];
    
    cell.path = newPath;
    
    if([self.files[indexPath.row] isEqualToString:NSHomeDirectory()]) {
        cell.textLabel.text = @"沙盒";
        cell.path = self.files[indexPath.row];
    }
    if([self.files[indexPath.row] isEqualToString:self.groupContainer]) {
        cell.textLabel.text = @"共享沙盒";
        cell.path = self.files[indexPath.row];
    }
    
    BOOL isDirectory;
    BOOL fileExists = [[NSFileManager defaultManager ] fileExistsAtPath:newPath isDirectory:&isDirectory];
    
	if (isDirectory ||
        [self.files[indexPath.row] isEqualToString:NSHomeDirectory()] ||
        [self.files[indexPath.row] isEqualToString:self.groupContainer])
		cell.imageView.image = [UIImage imageWithData:[[NSData alloc] initWithBase64EncodedString:self.folderBase options:NSDataBase64DecodingIgnoreUnknownCharacters] scale:3];
	else if ([[newPath pathExtension] isEqualToString:@"png"])

        cell.imageView.image = [UIImage imageWithContentsOfFile:newPath];
	else
		cell.imageView.image = nil;
    
    if([newPath containsString:@".zip"] && [[NSFileManager defaultManager] fileExistsAtPath:newPath]) {
        [cell.share setTitle:@"分享" forState:UIControlStateNormal];
    }else if(isDirectory) {
        [cell.share setTitle:@"压缩" forState:UIControlStateNormal];
    }

    cell.vc = self;
    return cell;
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
	NSString *newPath = [self.path stringByAppendingPathComponent:self.files[indexPath.row]];
	
	NSString *tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:newPath.lastPathComponent];
	
	NSError *error = nil;
	
	[[NSFileManager defaultManager] copyItemAtPath:newPath toPath:tmpPath error:&error];
	
	if (error)
		NSLog(@"ERROR: %@", error);
	
	UIActivityViewController *shareActivity = [[UIActivityViewController alloc] initWithActivityItems:@[[NSURL fileURLWithPath:tmpPath]] applicationActivities:nil];
	shareActivity.completionHandler = ^(NSString *activityType, BOOL completed){
		[[NSFileManager defaultManager] removeItemAtPath:tmpPath error:nil];
		
	};
	
	UIViewController *vc = [[UIViewController alloc] init];
	UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
	nc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
	
	[self.navigationController presentViewController:nc animated:YES completion:^{
		
	}];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	NSString *newPath = [self.path stringByAppendingPathComponent:self.files[indexPath.row]];
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if([cell.textLabel.text isEqualToString:@"沙盒"] || [cell.textLabel.text isEqualToString:@"共享沙盒"]) {
        newPath = self.files[indexPath.row];
    }
    
	BOOL isDirectory;
	BOOL fileExists = [[NSFileManager defaultManager ] fileExistsAtPath:newPath isDirectory:&isDirectory];
	
	
	if (fileExists) {
		if (isDirectory) {
			SandBoxTool *vc = [[SandBoxTool alloc] initWithPath:newPath];
            if([self.groupContainer isEqualToString:self.files[indexPath.row]]) {
                vc.title = @"共享沙盒";
            }
			[self.navigationController showViewController:vc sender:self];
		}
        
        else if([[newPath pathExtension] isEqualToString:@"png"]) {[self displayImage:indexPath.row];
            return;
        }
        
		else if ([FBCustomPreviewController canHandleExtension:[newPath pathExtension]]) {
			FBCustomPreviewController *preview = [[FBCustomPreviewController alloc] initWithFile:newPath];
			[self.navigationController pushViewController:preview animated:YES];
		}
		else {
			QLPreviewController *preview = [[QLPreviewController alloc] init];
			preview.dataSource = self;
			[self.navigationController pushViewController:preview animated:YES];
		}
	}
}

- (void)displayImage:(NSInteger )index {
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    browser.enableSwipeToDismiss = YES;
    // Set options
    browser.displayActionButton = YES; // Show action button to allow sharing, copying, etc (defaults to YES)
    browser.displayNavArrows = YES; // Whether to display left and right nav arrows on toolbar (defaults to NO)
    browser.displaySelectionButtons = NO; // Whether selection buttons are shown on each image (defaults to NO)
    browser.zoomPhotosToFill = YES; // Images that almost fill the screen will be initially zoomed to fill (defaults to YES)
    browser.alwaysShowControls = NO; // Allows to control whether the bars and controls are always visible or whether they fade away to show the photo full (defaults to NO)
    browser.enableGrid = YES; // Whether to allow the viewing of all the photo thumbnails on a grid (defaults to YES)
    browser.startOnGrid = NO; // Whether to start on the grid of thumbnails instead of the first photo (defaults to NO)
    browser.autoPlayOnAppear = NO; // Auto-play first video
    
    // Customise selection images to change colours if required
    browser.customImageSelectedIconName = @"ImageSelected.png";
    browser.customImageSelectedSmallIconName = @"ImageSelectedSmall.png";
    
    // Optionally set the current visible photo before displaying
    [browser setCurrentPhotoIndex:index];
    
    
    UINavigationController *photoNavigationController = [[UINavigationController alloc] initWithRootViewController:browser];
    photoNavigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:photoNavigationController animated:YES completion:nil];
    
}



#pragma mark - QuickLook

- (BOOL)previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id <QLPreviewItem>)item {
	
    return YES;
}

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller {
    return 1;
}

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index {
	
	NSString *newPath = [self.path stringByAppendingPathComponent:self.files[self.tableView.indexPathForSelectedRow.row]];
	
    return [NSURL fileURLWithPath:newPath];
}

//  MWPhotoBrowserDelegate
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return self.photos.count;
}

- (id<MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < self.photos.count) {
        return [self.photos objectAtIndex:index];
    }
    return nil;
}


@end



@implementation FBTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self buildUI];
    }
    return self;
}

- (void)buildUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    UIButton *delete = [self buildBtn:@"删除"];
    self.delete = delete;
    [self.contentView addSubview:delete];
    [delete mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.size.mas_equalTo(CGSizeMake(40, 30));
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
    
    UIButton *encode = [self buildBtn:@"压缩"];
    self.share = encode;
    [self.contentView addSubview:encode];
    [encode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(delete.mas_left).offset(-10);
        make.size.mas_equalTo(CGSizeMake(40, 30));
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
    self.imageView.clipsToBounds = YES;
    self.imageView.contentMode = UIViewContentModeScaleAspectFill;
}

- (UIButton *)buildBtn:(NSString *)title {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundColor:[UIColor grayColor]];
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:12];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonHander:) forControlEvents:UIControlEventTouchUpInside];
    return button;
}

- (void)buttonHander:(UIButton *)btn {
    if([btn.titleLabel.text isEqualToString:@"删除"]) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否删除?" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        [alert addAction:[UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            [[NSFileManager defaultManager] removeItemAtPath:self.path error:nil];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"event" object:self.path];
        }]];
        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        [self.vc presentViewController:alert animated:YES completion:nil];
        return;
    }
    if([btn.titleLabel.text isEqualToString:@"压缩"]) {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"MM-dd HH:mm:ss"];
        NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
        NSString *zipPath = [self.path stringByAppendingString:[NSString stringWithFormat:@"(%@).zip", currentDateStr]];
        if([[NSFileManager defaultManager] fileExistsAtPath:zipPath])
            [[NSFileManager defaultManager] removeItemAtPath:zipPath error:nil];
        
        [self.vc.ai startAnimating];
        [SSZipArchive createZipFileAtPath:zipPath withContentsOfDirectory:self.path keepParentDirectory:NO compressionLevel:9 password:zip_password AES:NO progressHandler:^(NSUInteger entryNumber, NSUInteger total) {
            if(entryNumber/total == 1) {
                [self.vc.ai stopAnimating];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"event" object:zipPath];
            }
        }];
        return;
    }
    if([btn.titleLabel.text isEqualToString:@"分享"]) {
        UIActivityViewController *ac = [[UIActivityViewController alloc] initWithActivityItems:@[[NSURL fileURLWithPath:self.path]] applicationActivities:nil];
        ac.excludedActivityTypes = @[UIActivityTypePostToTwitter, UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypePostToFacebook];
        [self.vc presentViewController:ac animated:YES
                            completion: nil];
        return;
    }
    
}



@end





@implementation FBCustomPreviewController

- (instancetype)initWithFile:(NSString *)file
{
    self = [super init];
    if (self) {
        
        textView = [[UITextView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        textView.editable = NO;
        textView.backgroundColor = [UIColor whiteColor];
        
        imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        imageView.backgroundColor = [UIColor whiteColor];
        
        [self loadFile:file];
        
    }
    return self;
}

+(BOOL)canHandleExtension:(NSString *)fileExt
{
    return ([fileExt isEqualToString:@"plist"] || [fileExt isEqualToString:@"strings"] || [fileExt isEqualToString:@"png"] || [fileExt isEqualToString:@"xcconfig"] );
}

-(void)loadFile:(NSString *)file
{
    if ([file.pathExtension isEqualToString:@"plist"] || [file.pathExtension isEqualToString:@"strings"])
    {
        NSDictionary *d = [NSDictionary dictionaryWithContentsOfFile:file];
        [textView setText:[d description]];
        self.view = textView;
    }
    else if ([file.pathExtension isEqualToString:@"xcconfig"])
    {
        NSString *d = [NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil];
        [textView setText:d];
        self.view = textView;
    }
    else
    {
        imageView.image = [UIImage imageWithContentsOfFile:file];
        self.view = imageView;
    }
    
    self.title = file.lastPathComponent;
}

@end

@implementation UIViewController (AutoShake)

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    // 如果是在预览页：
    if([NSStringFromClass(self.class) containsString:@"QL"]) {
        NSMutableArray *pathList = [NSMutableArray array];
        for(int i = 1; i < self.navigationController.viewControllers.count; i++) {
            SandBoxTool *vc = (SandBoxTool *)self.navigationController.viewControllers[i];
            if([vc isKindOfClass:SandBoxTool.class]) {
                [pathList addObject:vc.path];
            }
        }
        [[NSUserDefaults standardUserDefaults] setObject:pathList forKey:@"sandbox_last_path"];
        [self dismissViewControllerAnimated:YES completion:nil];
        return;
    }
    
    
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:[[SandBoxTool alloc] initWithGroupIdentifier:group_identifier]];
    [self presentViewController: navi animated:YES completion:nil];
    
    NSMutableArray *last = [[NSUserDefaults standardUserDefaults] objectForKey:@"sandbox_last_path"];
    if(last.count > 0 && remember_last_path) {
        for(int i = 0; i < last.count;i++) {
            SandBoxTool *vc = [[SandBoxTool alloc] initWithPath:last[i]];
            if(i == 0) {
                if([last[i] isEqualToString:NSHomeDirectory()]) {
                    vc.title = @"沙盒";
                }
                if([last[i] isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"sandbox_group_identifier"]]) {
                    vc.title = @"共享沙盒";
                }
            }
            [navi pushViewController:vc animated:NO];
        }
    }
}

#if touchs_begin_debug
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self presentViewController:[[UINavigationController alloc] initWithRootViewController:[[SandBoxTool alloc] initWithGroupIdentifier:group_identifier]] animated:YES completion:nil];
}
#endif



@end







